package com.tjsinfo.tjsoa.message.bo;

import java.util.Hashtable;
import java.util.List;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

import com.tjsinfo.tjsoa.addresslist.bo.IAddressListSystemUserBo;
import com.tjsinfo.tjsoa.addresslist.bo.IAddressListUserBo;
import com.tjsinfo.tjsoa.addresslist.vo.AddressListSystemUser;
import com.tjsinfo.tjsoa.message.JML;
import com.tjsinfo.tjsoa.message.vo.TjsMessage;
import com.tjsinfo.tjsoa.system.bo.ISystemUserBo;

public class TjsMessageIm  implements ITjsMessageBo{
	private final boolean starttrue=true;
	private ISystemUserBo   systemUserBo;
	private IAddressListSystemUserBo addressListSystemUserBo;

	public IAddressListSystemUserBo getAddressListSystemUserBo() {
		return addressListSystemUserBo;
	}

	public void setAddressListSystemUserBo(
			IAddressListSystemUserBo addressListSystemUserBo) {
		this.addressListSystemUserBo = addressListSystemUserBo;
	}

	public Boolean sendNewMessage(TjsMessage tjsMessage) {
		// TODO Auto-generated method stub
		send(tjsMessage);
		return starttrue;
	}

	/**
	 * 点对点发送
	 * @param tjsMessage
	 * @return
	 */
	private boolean send(TjsMessage tjsMessage)
	{
		JML jml = new JML();
		try {
			
			Configuration configuration = new PropertiesConfiguration("com/tjsinfo/tjsoa/message/properties/message.properties");
			jml.setEmail(configuration.getString("address"));
			jml.setPassword(configuration.getString("password"));
			String msnname = "";
			String feixin = "";
			AddressListSystemUser a = addressListSystemUserBo.findByUserId(tjsMessage.getRecuserid());
			if (a!=null) {
				if (a.getMsn()!=null && !"".equals(a.getMsn())) {
					msnname = a.getMsn();
					Hashtable table = new Hashtable();
					table.put(msnname, tjsMessage.getValue());
					
					feixin = a.getMobile();
					Hashtable table1 = new Hashtable();
					if (feixin!=null && !"".equals(feixin)) {
						table1.put(feixin, tjsMessage.getValue());
					}
					
					jml.sendMessageHashtable(table,table1);
				}
			}
		} catch (ConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
		return starttrue;
		
		
	}

	public ISystemUserBo getSystemUserBo() {
		return systemUserBo;
	}

	public void setSystemUserBo(ISystemUserBo systemUserBo) {
		this.systemUserBo = systemUserBo;
	}
	
	
}
